/**
 * 监测站点管理系统 DTO
 * 
 * 包含三个核心模块的数据传输对象：
 * 1. StationType - 测站类型相关 DTO
 * 2. StationInfo - 测站编码相关 DTO  
 * 3. MonitoringData - 监测数据相关 DTO
 * 
 * @author: [开发者名称]
 * @date: [创建日期]
 */

import { ApiProperty } from '@midwayjs/swagger';

// ========== 公共 DTO ==========

/**
 * 分页查询基础 DTO
 */
export class BasePageQuery {
    @ApiProperty({ description: '页码', example: 1, required: false })
    pageNum?: number = 1;

    @ApiProperty({ description: '每页数量', example: 10, required: false })
    pageSize?: number = 10;
}

/**
 * 分页结果 DTO
 */
export class PageResultDTO<T> {
    @ApiProperty({ description: '数据列表' })
    list: T[];

    @ApiProperty({ description: '总数量', example: 100 })
    total: number;

    @ApiProperty({ description: '当前页码', example: 1 })
    pageNum: number;

    @ApiProperty({ description: '每页数量', example: 10 })
    pageSize: number;

    @ApiProperty({ description: '总页数', example: 10 })
    totalPages: number;
}

/**
 * 通用响应 DTO
 */
export class CommonResponseDTO<T = any> {
    @ApiProperty({ description: '状态码', example: 200 })
    code: number;

    @ApiProperty({ description: '消息', example: '操作成功' })
    message: string;

    @ApiProperty({ description: '数据' })
    data?: T;

    @ApiProperty({ description: '时间戳', example: 1640995200000 })
    timestamp: number;
}

// ========== 测站类型相关 DTO ==========

/**
 * 创建测站类型 DTO
 */
export class CreateStationTypeDTO {
    @ApiProperty({ description: '测站类型编码', example: 'ST001' })
    stationTypeCode: string;

    @ApiProperty({ description: '测站类型名称', example: '水位监测站' })
    stationTypeName: string;

    @ApiProperty({ description: '数据类型编码', example: 'DT001', required: false })
    dataTypeCode?: string;

    @ApiProperty({ description: '数据类型名称', example: '水位数据', required: false })
    dataTypeName?: string;

    @ApiProperty({ description: '原始数据列名', example: 'water_level', required: false })
    originalColumnName?: string;

    @ApiProperty({ description: '原始数据列号', example: 1, required: false })
    originalColumnNumber?: number;
}

/**
 * 批量导入测站类型 DTO
 */
export class BatchImportStationTypeDTO {
    @ApiProperty({ description: '测站类型列表', type: [CreateStationTypeDTO] })
    stationTypeList: CreateStationTypeDTO[];
}

/**
 * 更新测站类型 DTO
 */
export class UpdateStationTypeDTO {
    @ApiProperty({ description: '测站类型编码', example: 'ST001', required: false })
    stationTypeCode?: string;

    @ApiProperty({ description: '测站类型名称', example: '水位监测站', required: false })
    stationTypeName?: string;

    @ApiProperty({ description: '数据类型编码', example: 'DT001', required: false })
    dataTypeCode?: string;

    @ApiProperty({ description: '数据类型名称', example: '水位数据', required: false })
    dataTypeName?: string;

    @ApiProperty({ description: '原始数据列名', example: 'water_level', required: false })
    originalColumnName?: string;

    @ApiProperty({ description: '原始数据列号', example: 1, required: false })
    originalColumnNumber?: number;
}

/**
 * 查询测站类型 DTO
 */
export class QueryStationTypeDTO extends BasePageQuery {
    @ApiProperty({ description: '测站类型编码', required: false })
    stationTypeCode?: string;

    @ApiProperty({ description: '测站类型名称', required: false })
    stationTypeName?: string;

    @ApiProperty({ description: '数据类型编码', required: false })
    dataTypeCode?: string;

    @ApiProperty({ description: '数据类型名称', required: false })
    dataTypeName?: string;
}

/**
 * 测站类型返回 DTO
 */
export class StationTypeResponseDTO {
    @ApiProperty({ description: 'ID', example: 'uuid' })
    id: string;

    @ApiProperty({ description: '测站类型编码', example: 'ST001' })
    stationTypeCode: string;

    @ApiProperty({ description: '测站类型名称', example: '水位监测站' })
    stationTypeName: string;

    @ApiProperty({ description: '数据类型编码', example: 'DT001' })
    dataTypeCode?: string;

    @ApiProperty({ description: '数据类型名称', example: '水位数据' })
    dataTypeName?: string;

    @ApiProperty({ description: '原始数据列名', example: 'water_level' })
    originalColumnName?: string;

    @ApiProperty({ description: '原始数据列号', example: 1 })
    originalColumnNumber?: number;

    @ApiProperty({ description: '创建时间' })
    createdAt: Date;

    @ApiProperty({ description: '更新时间' })
    updatedAt: Date;
}

// ========== 测站信息相关 DTO ==========

/**
 * 创建测站信息 DTO
 */
export class CreateStationInfoDTO {
    @ApiProperty({ description: '测站编码', example: 'ST001' })
    stcd: string;

    @ApiProperty({ description: '测站名称', example: '长江1号监测站', required: false })
    stnm?: string;

    @ApiProperty({ description: '经度', example: 116.407526, required: false })
    lon?: number;

    @ApiProperty({ description: '纬度', example: 39.904030, required: false })
    lat?: number;

    @ApiProperty({ description: '数据来源', example: '水文局', required: false })
    source?: string;

    @ApiProperty({ description: '地理位置信息', example: '北京市朝阳区', required: false })
    geo?: string;

    @ApiProperty({ description: '测站类型编码', example: 'ST001', required: false })
    stationTypeCode?: string;
}

/**
 * 更新测站信息 DTO
 */
export class UpdateStationInfoDTO {
    @ApiProperty({ description: '测站编码', example: 'ST001', required: false })
    stcd?: string;

    @ApiProperty({ description: '测站名称', example: '长江1号监测站', required: false })
    stnm?: string;

    @ApiProperty({ description: '经度', example: 116.407526, required: false })
    lon?: number;

    @ApiProperty({ description: '纬度', example: 39.904030, required: false })
    lat?: number;

    @ApiProperty({ description: '数据来源', example: '水文局', required: false })
    source?: string;

    @ApiProperty({ description: '地理位置信息', example: '北京市朝阳区', required: false })
    geo?: string;

    @ApiProperty({ description: '测站类型编码', example: 'ST001', required: false })
    stationTypeCode?: string;
}

/**
 * 查询测站信息 DTO
 */
export class QueryStationInfoDTO extends BasePageQuery {
    @ApiProperty({ description: '测站编码', required: false })
    stcd?: string;

    @ApiProperty({ description: '测站名称', required: false })
    stnm?: string;

    @ApiProperty({ description: '数据来源', required: false })
    source?: string;

    @ApiProperty({ description: '最小经度', required: false })
    minLon?: number;

    @ApiProperty({ description: '最大经度', required: false })
    maxLon?: number;

    @ApiProperty({ description: '最小纬度', required: false })
    minLat?: number;

    @ApiProperty({ description: '最大纬度', required: false })
    maxLat?: number;

    @ApiProperty({ description: '测站类型编码', required: false })
    stationTypeCode?: string;
}

/**
 * 测站信息返回 DTO
 */
export class StationInfoResponseDTO {
    @ApiProperty({ description: 'ID', example: 'uuid' })
    id: string;

    @ApiProperty({ description: '测站编码', example: 'ST001' })
    stcd: string;

    @ApiProperty({ description: '测站名称', example: '长江1号监测站' })
    stnm?: string;

    @ApiProperty({ description: '经度', example: 116.407526 })
    lon?: number;

    @ApiProperty({ description: '纬度', example: 39.904030 })
    lat?: number;

    @ApiProperty({ description: '数据来源', example: '水文局' })
    source?: string;

    @ApiProperty({ description: '地理位置信息', example: '北京市朝阳区' })
    geo?: string;
    
    @ApiProperty({ description: '测站类型编码', example: 'ST001' })
    stationTypeCode?: string;

    @ApiProperty({ description: '创建时间' })
    createdAt: Date;

    @ApiProperty({ description: '更新时间' })
    updatedAt: Date;
}

/**
 * 批量导入测站信息 DTO
 */
export class BatchImportStationInfoDTO {
    @ApiProperty({ description: '测站信息列表', type: [CreateStationInfoDTO] })
    stationInfoList: CreateStationInfoDTO[];
}

// ========== 监测数据相关 DTO ==========

/**
 * 创建监测数据 DTO
 */
export class CreateMonitoringDataDTO {
    @ApiProperty({ description: '测站编码', example: 'ST001' })
    stationCode: string;

    @ApiProperty({ description: '数据类型', example: 'water_level', required: false })
    dataType?: string;

    @ApiProperty({ description: '测站类型编码', example: 'ST001', required: false })
    stationTypeCode?: string;

    @ApiProperty({ description: '测站类型名称', example: '水位监测站', required: false })
    stationTypeName?: string;

    @ApiProperty({ description: '监测日期', example: '2024-01-01T00:00:00Z', required: false })
    monitoringDate?: Date;

    @ApiProperty({ description: '监测数据值', example: 12.5, required: false })
    monitoringValue?: number;
}

/**
 * 更新监测数据 DTO
 */
export class UpdateMonitoringDataDTO {
    @ApiProperty({ description: '测站编码', example: 'ST001', required: false })
    stationCode?: string;

    @ApiProperty({ description: '数据类型', example: 'water_level', required: false })
    dataType?: string;

    @ApiProperty({ description: '测站类型编码', example: 'ST001', required: false })
    stationTypeCode?: string;

    @ApiProperty({ description: '测站类型名称', example: '水位监测站', required: false })
    stationTypeName?: string;

    @ApiProperty({ description: '监测日期', example: '2024-01-01T00:00:00Z', required: false })
    monitoringDate?: Date;

    @ApiProperty({ description: '监测数据值', example: 12.5, required: false })
    monitoringValue?: number;
}

/**
 * 查询监测数据 DTO - 支持 dataTypes 多选
 */
export class QueryMonitoringDataDTO extends BasePageQuery {
    @ApiProperty({ description: '测站编码', required: false })
    stationCode?: string;

    @ApiProperty({ description: '数据类型（单选，向后兼容）', required: false })
    dataType?: string;

    @ApiProperty({ 
        description: '数据类型列表（多选，支持字符串或数组）', 
        type: [String], 
        required: false,
        example: ['water_level', 'temperature', 'humidity']
    })
    dataTypes?: string[] | string; // 支持联合类型

    @ApiProperty({ description: '测站类型编码', required: false })
    stationTypeCode?: string;

    @ApiProperty({ description: '测站类型名称', required: false })
    stationTypeName?: string;

    @ApiProperty({ description: '开始日期', required: false })
    startDate?: Date;

    @ApiProperty({ description: '结束日期', required: false })
    endDate?: Date;

    @ApiProperty({ description: '最小监测值', required: false })
    minValue?: number;

    @ApiProperty({ description: '最大监测值', required: false })
    maxValue?: number;
}
/**
 * 监测数据返回 DTO
 */
export class MonitoringDataResponseDTO {
    @ApiProperty({ description: 'ID', example: 'uuid' })
    id: string;

    @ApiProperty({ description: '测站编码', example: 'ST001' })
    stationCode: string;

    @ApiProperty({ description: '测站名称', example: '长江1号监测站', required: false })
    stationName?: string;

    @ApiProperty({ description: '数据类型', example: 'water_level' })
    dataType?: string;

    @ApiProperty({ description: '数据类型名称', example: '水位数据' })
    dataTypeName?: string;

    @ApiProperty({ description: '测站类型编码', example: 'ST001' })
    stationTypeCode?: string;

    @ApiProperty({ description: '测站类型名称', example: '水位监测站' })
    stationTypeName?: string;

    @ApiProperty({ description: '监测日期' })
    monitoringDate?: Date;

    @ApiProperty({ description: '监测数据值', example: 12.5 })
    monitoringValue?: number;

    @ApiProperty({ description: '创建时间' })
    createdAt: Date;

    @ApiProperty({ description: '更新时间' })
    updatedAt: Date;
}

/**
 * 批量导入监测数据 DTO
 */
export class BatchImportMonitoringDataDTO {
    @ApiProperty({ description: '监测数据列表', type: [CreateMonitoringDataDTO] })
    monitoringDataList: CreateMonitoringDataDTO[];
}

/**
 * 批量删除 DTO
 */
export class BatchDeleteDTO {
    @ApiProperty({ description: 'ID列表', example: ['uuid1', 'uuid2'] })
    ids: string[];
}

/**
 * 数据统计返回 DTO
 */
export class DataStatisticsDTO {
    @ApiProperty({ description: '测站编码', example: 'ST001' })
    stationCode: string;

    @ApiProperty({ description: '测站名称', example: '长江1号监测站' })
    stationName?: string;

    @ApiProperty({ description: '测站类型编码', example: 'ST001' })
    stationTypeCode?: string;

    @ApiProperty({ description: '测站类型名称', example: '水位监测站' })
    stationTypeName?: string;

    @ApiProperty({ description: '数据总数', example: 1000 })
    totalCount: number;

    @ApiProperty({ description: '最新数据时间' })
    latestDate?: Date;

    @ApiProperty({ description: '最早数据时间' })
    earliestDate?: Date;

    @ApiProperty({ description: '平均值', example: 12.5 })
    avgValue?: number;

    @ApiProperty({ description: '最大值', example: 25.0 })
    maxValue?: number;

    @ApiProperty({ description: '最小值', example: 5.0 })
    minValue?: number;
}